package com.xja.controller;

import com.xja.entity.Active;
import com.xja.service.ActiveService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/active")
public class ActiveController {
    private Logger logger = LoggerFactory.getLogger(CourseController.class);
    @Reference(url = "dubbo://localhost:20884")
    private ActiveService activeService;

    /*获取仍有名额的活动*/
    @RequestMapping("/getActive")
    public String getActive(Model model){
        System.out.println("调用了获取全部活动的方法");
        System.out.println(activeService);
        List<Active> actives = activeService.getActives();
        model.addAttribute("actives",actives);
        return "active";
    }

    @RequestMapping("/getActiveById")
    public String getActiveById(Integer aid,Model model){
        System.out.println("调用了获取活动详情的方法");
        Active active = activeService.getActiveById(aid);
        model.addAttribute("active",active);
        return "active-details";
    }

    @RequestMapping("/addPerson")
    public String addPerson(Integer aid){
        System.out.println("调用了报名的方法");
        boolean flag = activeService.addPerson(aid);
        if(flag){
            return "redirect:/active/getActive";
        }
        return "redirect:/active/getActiveById?aid="+aid;
    }
}
